package main

import (
	"context"
	"fmt"
	"go_stu/src/6_demo_grpc/pb"

	"google.golang.org/grpc"
)

func main() {
	// 1、链接 grpc 服务
	grpcConn, err := grpc.Dial("127.0.0.1:8088", grpc.WithInsecure()) // 表示安全，在grpc得带
	if err != nil {
		fmt.Println("grpc.Dial error is ", err)
		return
	}
	defer grpcConn.Close()
	// 2、初始化 grpc 客户端
	grpcClient := pb.NewSayNameClient(grpcConn)

	// 创建并初始化Teacher对象
	var teacher pb.Teacher
	teacher.Name = "wjf"
	teacher.Age = 18

	// 3、调用远程服务
	// context.TODO(): 空对象
	t, err := grpcClient.SayHello(context.TODO(), &teacher)
	fmt.Println(t, err)
}
